*** REPLICATION TOOLKIT ***

* AUTHORS: CIMINELLI DUVAL FURCERI 

* ARTICLE: EMPLOYMENT PROTECTION DEREGULATION AND LABOR SHARES IN ADVANCED ECONOMIES 

* JOURNAL: REVIEW OF ECONOMICS AND STATISTICS

* OUTPUT: FIGURE E6 (ONLINE APPENDIX)

***************************

cd ""

use "DTA files/Dataset", clear

global se90 = 1.6

**************** TIME TRENDS IN LABOR SHARE BY INDUSTRY *******************

gen a = 100*lab/va
egen trend = group(year)

* Create matrix where to store the results
egen id1 = group(industry)
sum id1
local max = r(max)
mat trends = J(`max',6,.)

* Perform regression and save relevant results
forvalues i=1/`max' {
quietly sum a if id1==`i'
local sc = r(N)
if `sc' != 0 {
xtset id_cross_section year
quietly xtreg a trend if id1==`i', fe
matrix results = r(table)
matrix trends[`i',1]=results[1,1]
matrix trends[`i',2]=results[2,1]
matrix trends[`i',3]=results[4,1]
}
}

* Assign names to the rows of the matrix
matrix rownames trends = Food&Beverages&Tobacco Textiles Wood&Paper&Reproduction Coke&Petroleum Chemicals Rubber&Plastics BasicMetals Electrical&Optical Machinery&Equipment TransportEquipment OthersManufacturing  Wholesale&RetailMotor WholesaleEx-Motor RetailEx-Motor Transport&Storage Postal&Courier Publishing&Audiovisual Telecommunications IT&Others Agriculture Mining&Quarrying  Utilities Construction Accomodation&FoodServices Financial&Insurance RealEstate Professional&SupportActivities PA&Defense&SS Education Health&Social Arts&Recreation OtherServiceActivities
matrix trans_trends = trends'
forvalues j=1/2 {
matrix rowtest`j' = trans_trends["c`j'", 1...]
}
local names : colnames rowtest1
local n_names : word count `names'
gen var_colnames = ""
forval i=1/`n_names' {
local this_name = "`:word `i' of `names''"
replace var_colnames = "`this_name'" if _n == `i'
}
forvalues j=1/2 {
matrix trans_rowtest`j' = rowtest`j''
}

* Create new variable tran_rowtest from the transpose of matrix rowtest (In this matrix the linear trends are stored)
svmat trans_rowtest1, name(tot_beta)
svmat trans_rowtest2, name(tot_se)
 
* Graph 
gen tot_ci_p = tot_beta1+$se90*tot_se1
gen tot_ci_n = tot_beta1-$se90*tot_se1

* Names for legend
sort tot_beta1
g tot_order=_n
replace tot_order = . if tot_beta1==.

sum tot_order
local max = r(max)
forvalues j=1/`max' {
local n`j' = var_colnames[`j']
}

* Graph
eclplot tot_beta tot_ci_p tot_ci_n tot_order, yline(0, lcolor(black)) xtitle("") ytitle("") graphregion(color(white)) estopts(barwidth(0.75) bcolor(green) blcolor(black))  ciopts(blcolor(black)) eplottype(bar)  ////
xlabel(1 "`n1'" 2 "`n2'" 3 "`n3'" 4 "`n4'" 5 "`n5'" 6 "`n6'" 7 "`n7'" 8 "`n8'" 9 "`n9'" 10 "`n10'" 11 "`n11'"  12 "`n12'" 13 "`n13'" 14 "`n14'" 15 "`n15'" 16 "`n16'" 17 "`n17'" 18 "`n18'" 19 "`n19'" 20 "`n20'" 21 "`n21'" 22 "`n22'" 23 "`n23'" 24 "`n24'" 25 "`n25'" 26 "`n26'" 27 "`n27'" 28 "`n28'" 29 "`n29'" 30 "`n30'" 31 "`n31'" 32 "`n32'", labsize(small) angle(60) labgap(small) noticks)
graph export "Figures/E6.png", replace
